package com.itheima.sc.impl.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.sc.api.order.OmsOrderReturnReasonApi;
import com.itheima.sc.mapper.order.OsmOrderReturnReasonMapper;
import com.itheima.sc.pojo.order.OmsOrderReturnReason;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;

@DubboService
public class OmsOrderReturnReasonImpl implements OmsOrderReturnReasonApi {
    @Autowired
    OsmOrderReturnReasonMapper osmOrderReturnReasonMapper;

    @Override
    public Page<OmsOrderReturnReason> listOmsOrderReturnApply(Integer page, Integer size) {
        Page<OmsOrderReturnReason>ipage=new Page<>(page,size);
        ipage = osmOrderReturnReasonMapper.selectPage(ipage,new LambdaQueryWrapper<>());
        return ipage;
    }

    @Override
    public void create(OmsOrderReturnReason omsOrderReturnReason) {
        osmOrderReturnReasonMapper.insert(omsOrderReturnReason);
    }

    @Override
    public void deletByIds(ArrayList<Long> ids) {
        osmOrderReturnReasonMapper.deleteBatchIds(ids);
    }

    @Override
    public void updateStatus(ArrayList<Long> ids, Integer status) {
        LambdaUpdateWrapper<OmsOrderReturnReason> updateWrapper = new LambdaUpdateWrapper<>();
        for (Long id : ids) {
            OmsOrderReturnReason omsOrderReturnReason = new OmsOrderReturnReason();
            omsOrderReturnReason.setStatus(status);
            updateWrapper.eq(OmsOrderReturnReason::getId, id);
            osmOrderReturnReasonMapper.update(omsOrderReturnReason, updateWrapper);
        }
    }

    @Override
    public void updateReason(Long id, OmsOrderReturnReason omsOrderReturnReason) {
        LambdaUpdateWrapper<OmsOrderReturnReason> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(OmsOrderReturnReason::getId, id);
        osmOrderReturnReasonMapper.update(omsOrderReturnReason, updateWrapper);

    }

    @Override
    public OmsOrderReturnReason getReason(Long id) {
        return osmOrderReturnReasonMapper.selectById(id);
    }


}
